<?php
include_once 'function-widget.php';
// ========================================================================================================================================
// Bloco de notícias em destaque, mostra n notícia
// ========================================================================================================================================
class news_1 extends WP_Widget {	

	function __construct(){
		parent::__construct('news_1', 'AVPT_News Horizontal', array('description' => 'Mostra um bloco com n notícia'));
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);
		$title = empty ($instance['title']) ? 'Notícias' : apply_filters('widget_title', $instance['title']);
		$categoria = empty ($instance['categoria']) ? 'noticias' : apply_filters('categoria', $instance['categoria']);
		$icon = empty ($instance['icon']) ? 'noticias' : apply_filters('icon', $instance['icon']);
		$qtde = empty ($instance['qtde']) ? '4' : apply_filters('qtde', $instance['qtde']);
		$corte = empty ($instance['corte']) ? '0' : apply_filters('corte', $instance['corte']);  
		$up = empty ($instance['up']) ? '20' : apply_filters('up', $instance['up']);
		$down = empty ($instance['down']) ? '20' : apply_filters('down', $instance['down']);?>
		<div class="<?php echo 'vertical_space_'.$up?>"></div>
		<?php do_bloco_destaque_noticias ($title, $icon, $categoria, $qtde, $corte);?>
		<div class="<?php echo 'vertical_space_'.$down ?>"></div>
	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['categoria'] = strip_tags($new_instance['categoria']);
		$instance['icon'] = strip_tags($new_instance['icon']);
		$instance['qtde'] = strip_tags($new_instance['qtde']);
		$instance['corte'] = strip_tags($new_instance['corte']);
		$instance['up'] = strip_tags($new_instance['up']);
		$instance['down'] = strip_tags($new_instance['down']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('title' => '', 'categoria' => '', 'icon' => '', 'qtde' => '', 'corte' => '', 'up' => '', 'down' => ''));
		$title = strip_tags($instance['title']);
		$categoria = strip_tags($instance['categoria']);
		$icon = strip_tags($instance['icon']);
		$qtde = strip_tags($instance['qtde']);
		$corte = strip_tags($instance['corte']);
		$up = strip_tags($instance['up']);
		$down = strip_tags($instance['down']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Título:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Categoria:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('categoria'); ?>" name="<?php echo $this->get_field_name('categoria'); ?>" value="<?php echo esc_attr($categoria); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('icon');?>"><?php _e('Icone:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('icon'); ?>" name="<?php echo $this->get_field_name('icon'); ?>" value="<?php echo esc_attr($icon); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('qtde');?>"><?php _e('Quantidade:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('qtde'); ?>" name="<?php echo $this->get_field_name('qtde'); ?>" value="<?php echo esc_attr($qtde); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('corte');?>"><?php _e('Corte:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('corte'); ?>" name="<?php echo $this->get_field_name('corte'); ?>" value="<?php echo esc_attr($corte); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('up');?>"><?php _e('Espaço acima em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('up'); ?>" name="<?php echo $this->get_field_name('up'); ?>" value="<?php echo esc_attr($up); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('down');?>"><?php _e('Espaço abaixo em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('down'); ?>" name="<?php echo $this->get_field_name('down'); ?>" value="<?php echo esc_attr($down); ?>">
		</p>
		<?php		
	}
}
// ========================================================================================================================================



// ========================================================================================================================================
// Bloco de notícias em destaque, mostra n notícia
// ========================================================================================================================================
class news_1_1 extends WP_Widget {	

	function __construct(){
		parent::__construct('news_1_1', 'AVPT_News', array('description' => 'Mostra um bloco com n notícia escolhidas'));
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);
		$title = empty ($instance['title']) ? 'Notícias' : apply_filters('widget_title', $instance['title']);
		$categoria = empty ($instance['categoria']) ? 'noticias' : apply_filters('categoria', $instance['categoria']);
		$icon = empty ($instance['icon']) ? 'noticias' : apply_filters('icon', $instance['icon']);
		$slug = empty ($instance['slug']) ? '0' : apply_filters('corte', $instance['slug']);  
		$up = empty ($instance['up']) ? '20' : apply_filters('up', $instance['up']);
		$down = empty ($instance['down']) ? '20' : apply_filters('down', $instance['down']);?>
		<div class="<?php echo 'vertical_space_'.$up?>"></div>
		<?php do_bloco_destaque_noticias_manual ($title, $icon, $categoria, $qtde, $corte, $slug);?>
		<div class="<?php echo 'vertical_space_'.$down ?>"></div>
	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['categoria'] = strip_tags($new_instance['categoria']);
		$instance['icon'] = strip_tags($new_instance['icon']);
		$instance['slug'] = strip_tags($new_instance['slug']);
		$instance['up'] = strip_tags($new_instance['up']);
		$instance['down'] = strip_tags($new_instance['down']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('title' => '', 'categoria' => '', 'icon' => '', 'slug' => '', 'up' => '', 'down' => ''));
		$title = strip_tags($instance['title']);
		$categoria = strip_tags($instance['categoria']);
		$icon = strip_tags($instance['icon']);
		$qtde = strip_tags($instance['qtde']);
		$slug = strip_tags($instance['slug']);
		$up = strip_tags($instance['up']);
		$down = strip_tags($instance['down']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Título:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Categoria:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('categoria'); ?>" name="<?php echo $this->get_field_name('categoria'); ?>" value="<?php echo esc_attr($categoria); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('icon');?>"><?php _e('Icone:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('icon'); ?>" name="<?php echo $this->get_field_name('icon'); ?>" value="<?php echo esc_attr($icon); ?>">
		</p>		
		<p>
		  <label for="<?php echo $this->get_field_id('slug');?>"><?php _e('slug:', 'tga') ?></label>
		  <textarea rows="4" cols="50" class="widefat" id="<?php echo $this->get_field_id('slug'); ?>" name="<?php echo $this->get_field_name('slug'); ?>" value="<?php echo esc_attr($slug); ?>"></textarea>
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('up');?>"><?php _e('Espaço acima em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('up'); ?>" name="<?php echo $this->get_field_name('up'); ?>" value="<?php echo esc_attr($up); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('down');?>"><?php _e('Espaço abaixo em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('down'); ?>" name="<?php echo $this->get_field_name('down'); ?>" value="<?php echo esc_attr($down); ?>">
		</p>
		<?php		
	}
}
// ========================================================================================================================================





// ========================================================================================================================================
// Bloco de notícias em destaque, mostra n notícia
// ========================================================================================================================================
class news_2 extends WP_Widget {	

	function __construct(){
		parent::__construct('news_2', 'AVPT_News Vertical 1', array('description' => 'Mostra um bloco com 4 notícia na vertical'));
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);
		$title = empty ($instance['title']) ? 'Notícias' : apply_filters('widget_title', $instance['title']);
		$categoria = empty ($instance['categoria']) ? 'noticias' : apply_filters('categoria', $instance['categoria']);
		$icon = empty ($instance['icon']) ? 'noticias' : apply_filters('icon', $instance['icon']);
		$corte = empty ($instance['corte']) ? '0' : apply_filters('corte', $instance['corte']); 
		$up = empty ($instance['up']) ? '20' : apply_filters('up', $instance['up']);
		$down = empty ($instance['down']) ? '20' : apply_filters('down', $instance['down']);?>
		<div class="<?php echo 'vertical_space_'.$up?>"></div>
		<?php do_bloco_destaque_noticias_2 ($title, $icon, $categoria, $corte);?>
		<div class="<?php echo 'vertical_space_'.$down ?>"></div>
	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['categoria'] = strip_tags($new_instance['categoria']);
		$instance['icon'] = strip_tags($new_instance['icon']);
		$instance['corte'] = strip_tags($new_instance['corte']);
		$instance['up'] = strip_tags($new_instance['up']);
		$instance['down'] = strip_tags($new_instance['down']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('title' => '', 'categoria' => '', 'icon' => '', 'corte' => '', 'up' => '', 'down' => ''));
		$title = strip_tags($instance['title']);
		$categoria = strip_tags($instance['categoria']);
		$icon = strip_tags($instance['icon']);
		$corte = strip_tags($instance['corte']);
		$up = strip_tags($instance['up']);
		$down = strip_tags($instance['down']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Título:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Categoria:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('categoria'); ?>" name="<?php echo $this->get_field_name('categoria'); ?>" value="<?php echo esc_attr($categoria); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('icon');?>"><?php _e('Icone:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('icon'); ?>" name="<?php echo $this->get_field_name('icon'); ?>" value="<?php echo esc_attr($icon); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('corte');?>"><?php _e('Corte:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('corte'); ?>" name="<?php echo $this->get_field_name('corte'); ?>" value="<?php echo esc_attr($corte); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('up');?>"><?php _e('Espaço acima em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('up'); ?>" name="<?php echo $this->get_field_name('up'); ?>" value="<?php echo esc_attr($up); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('down');?>"><?php _e('Espaço abaixo em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('down'); ?>" name="<?php echo $this->get_field_name('down'); ?>" value="<?php echo esc_attr($down); ?>">
		</p>
		<?php		
	}
}
// ========================================================================================================================================


// ========================================================================================================================================
// Bloco de notícias em destaque, mostra n notícia
// ========================================================================================================================================
class news_3 extends WP_Widget {	

	function __construct(){
		parent::__construct('news_3', 'AVPT_News Vertical 2', array('description' => 'Mostra um bloco com 1, 2, 3 ou 4 notícia na vertical'));
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);
		$title = empty ($instance['title']) ? 'Notícias' : apply_filters('widget_title', $instance['title']);
		$categoria = empty ($instance['categoria']) ? 'noticias' : apply_filters('categoria', $instance['categoria']);
		$icon = empty ($instance['icon']) ? 'noticias' : apply_filters('icon', $instance['icon']);
		$qtde = empty ($instance['qtde']) ? '4' : apply_filters('qtde', $instance['qtde']); 
		$corte = empty ($instance['corte']) ? '0' : apply_filters('corte', $instance['corte']); 
		$up = empty ($instance['up']) ? '20' : apply_filters('up', $instance['up']);
		$down = empty ($instance['down']) ? '20' : apply_filters('down', $instance['down']);?>
		<div class="<?php echo 'vertical_space_'.$up?>"></div>
		<?php do_bloco_destaque_noticias_3 ($title, $icon, $categoria, $qtde, $corte);?>
		<div class="<?php echo 'vertical_space_'.$down ?>"></div>
	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['categoria'] = strip_tags($new_instance['categoria']);
		$instance['icon'] = strip_tags($new_instance['icon']);
		$instance['qtde'] = strip_tags($new_instance['qtde']);
		$instance['corte'] = strip_tags($new_instance['corte']);
		$instance['up'] = strip_tags($new_instance['up']);
		$instance['down'] = strip_tags($new_instance['down']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('title' => '', 'categoria' => '', 'icon' => '', 'qtde' => '', 'corte' => '', 'up' => '', 'down' => ''));
		$title = strip_tags($instance['title']);
		$categoria = strip_tags($instance['categoria']);
		$icon = strip_tags($instance['icon']);
		$qtde = strip_tags($instance['qtde']);
		$corte = strip_tags($instance['corte']);
		$up = strip_tags($instance['up']);
		$down = strip_tags($instance['down']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Título:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Categoria:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('categoria'); ?>" name="<?php echo $this->get_field_name('categoria'); ?>" value="<?php echo esc_attr($categoria); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('icon');?>"><?php _e('Icone:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('icon'); ?>" name="<?php echo $this->get_field_name('icon'); ?>" value="<?php echo esc_attr($icon); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('qtde');?>"><?php _e('Quantidade:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('qtde'); ?>" name="<?php echo $this->get_field_name('qtde'); ?>" value="<?php echo esc_attr($qtde); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('corte');?>"><?php _e('Corte:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('corte'); ?>" name="<?php echo $this->get_field_name('corte'); ?>" value="<?php echo esc_attr($corte); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('up');?>"><?php _e('Espaço acima em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('up'); ?>" name="<?php echo $this->get_field_name('up'); ?>" value="<?php echo esc_attr($up); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('down');?>"><?php _e('Espaço abaixo em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('down'); ?>" name="<?php echo $this->get_field_name('down'); ?>" value="<?php echo esc_attr($down); ?>">
		</p>
		<?php		
	}
}
// ========================================================================================================================================




